// $Id$
// Licensed under Apache License Version 2.0
// See: http://www.apache.org/licenses/LICENSE-2.0.html
package de.servicezombie.tests;

import java.util.Date;

import de.servicezombie.tcmdb.rest.vo.ActivityStatus;
import de.servicezombie.tcmdb.rest.vo.Severity;
import de.servicezombie.tcmdb.rest.vo.TimeUnit;
import de.servicezombie.tcmdb.rest.vo.WsAccessRecord;
import de.servicezombie.tcmdb.rest.vo.WsApplication;
import de.servicezombie.tcmdb.rest.vo.WsAuthor;
import de.servicezombie.tcmdb.rest.vo.WsTestcaseDefinition;

public class DataFactoryForWsTestDefinition extends AbstractDataFactory<WsTestcaseDefinition> {

	@Override
	protected WsTestcaseDefinition buildDefaultInstance(int index) {
		WsTestcaseDefinition result = new WsTestcaseDefinition();
		
		result.getEffort().setValue(15);
		result.getEffort().setTimeUnit(TimeUnit.MINUTES);
		
		configureApplications(result);
		configureAccessRecord(result);
		configureOwner(result);
		
		result.setTitle(addIndex("default testcase title",index));
		result.setDescription(addIndex("default testcase description",index));
		result.setExpectedResult(addIndex("default testcase expectedResult",index));
		result.setTags(addIndex("unittest", index));
		result.setSeverity(Severity.BLOCKER);
		result.setStatus(ActivityStatus.ACTIVE);
		result.setTags("factory unit-test");
		
		return result;
	}

	private void configureOwner(WsTestcaseDefinition result) {
		WsAuthor author = new WsAuthor();
		author.setEmail("factory@localhost");
		author.setId("factory-owner-process");
		author.setName("WstestDefinitionFactory");
		result.setOwner(author);
	}

	private void configureAccessRecord(WsTestcaseDefinition result) {
		WsAccessRecord access = new WsAccessRecord();
		access.setCreated(new Date());
		access.setLastChanged(new Date());
		access.setIdOfChanger("factory-object");
		access.setIdOfCreator("factory-object");
		result.setAccess(access );
	}

	private void configureApplications(WsTestcaseDefinition result) {
		WsApplication application = new WsApplication();
		application.setName("UNIT TEST APPLICATION");
		application.setProject("RELEASE 3");
		result.addApplication(application);
	}

}
